import numpy as np

# 示例数据
X = np.array([1, 2, 3, 4, 5])#这里是x和y的实际值
Y = np.array([2, 4, 6, 8, 10])

# 初始化参数
w = 0
b = 0

# 学习率和迭代次数
alpha = 0.01
iterations = 1000

# 梯度下降过程
m = len(X)
for i in range(iterations):
    # 预测值
    Y_pred = w * X + b
    # 计算梯度
    dw = (-2/m) * sum(X * (Y - Y_pred))
    db = (-2/m) * sum(Y - Y_pred)
    # 更新参数
    w -= alpha * dw
    b -= alpha * db

print(f"通过梯度下降得到的权重: {w:.3f}, 偏差: {b:.3f}")
